<?

/**
* Fetch login
* Check if the user, pass and company is exist and active
* return true  if the user is active and exists
*        false if null return from the db fetch
*
* @param  string    $COracle
* @param  string    $user
* @param  string    $pass
* @param  string    $company
* @param  string    $srcDb
* @return booelan   true on success and false on failed
*
*/
function fetchLogin(&$COracle,
                    &$user, 
                    &$pass, 
                    &$company,
                    &$srcDb){
  
  $query  = "SELECT USERID ".
            "FROM ".$srcDb." ".
            "WHERE  USERID='".$user."' ".
                    "AND PASSWORD='".$pass."' ".
                    "AND COMPANY='".$company."' ";
  
  $COracle->execFetchQuery($query,
                           $nrows,
                           $result);
  if($nrows > 0){
    
    return true;
  }else{
  
    return false;
  }
}

/**
* Fetch currently selected levelD
*
* @param  string    $COracle
* @param  string    $srcDb
* @param  string    $selected
*
*/
function fetchSelLevelD(&$COracle,
                        &$srcDb,
                        &$selected){

  $query  = "SELECT LEVELD ".
            "FROM ".$srcDb." ".
            "WHERE  STATUS='"._ACTIVE."' ";
  
  $COracle->execFetchQuery($query,
                           $nrows,
                           $result);
  
  $selected = $result["LEVELD"][0];
}

/**
* fetch the last number of a table
*
* @param  string    $COracle
* @param  string    $today_date
* @param  string    $srcDb
* @param  string    $lastNo
*
*/
function fetchLastNoByDate(&$COracle,
                           $today_date,
                           &$srcDb,
                           &$lastNo){
     
  $query  = "SELECT NO 
             FROM ".$srcDb." 
             WHERE  TR_DATE=TO_DATE('".$today_date."', 'dd-mm-YYYY') 
             ORDER BY NO DESC ";
  
  $COracle->execFetchQuery($query,
                           $nrows,
                           $result);
  
  /**
  * Check if there is number in this date
  * YES: fetch it and increment
  * NO : Assign 1 as the first number
  *
  */
  if($nrows > 0){
  
    $lastNo = $result["NO"][0] + 1;
  }else{
    
    $lastNo = 1;
  }
}

/**
* fetch the values data
*
* @param  string  $COracle  
* @param  string  $userId  
* @param  string  $srcValues
* @param  string  $srcDbHdr
* @param  string  $srcDbDtl
* @param  string  $theResult
*
*/
function fetchUnserialize(&$COracle,
                          &$userId,
                          &$srcValues,
                          &$srcDbHdr,
                          &$srcDbDtl,
                          &$theResult){
                        
  
}

/**
* fetch the current number of sequence 
* of this sequence name
* 
* @param  string  $COracle
* @param  string  $thisSequence
* @param  string  $thisPeriode
* @param  string  $srcDb
* @param  string  $srcJidIndex
*
*/
function fetchCurSequence(&$COracle,
          	              &$thisSequence,
          	              &$thisPeriode,
          	              &$srcDb,
          	              &$srcJidIndex){
  
  $srcPeriode = "TO_DATE('".$thisPeriode."','mm-YYYY')";
                  
  $query  = "SELECT SEQ_NUMBER
             FROM ".$srcDb." 
             WHERE  SEQ_NAME='".$thisSequence."' 
                    AND PERIODE=".$srcPeriode." ";
  
  $COracle->execFetchQuery($query,
                           $nrows,
                           $result);
  
  $srcJidIndex = $result["SEQ_NUMBER"][0];
}
?>